package com.xt.partjobback.controller;


import com.xt.partjobback.constant.ResultDTO;
import com.xt.partjobback.exception.ParamsException;
import com.xt.partjobback.exception.PermissionsException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author leotong
 */
@RestControllerAdvice
public class ExceptionController {

    @ExceptionHandler(Exception.class)
    public ResultDTO<String> handleException(Exception e) {
        return ResultDTO.error(e.getMessage());
    }
    @ExceptionHandler(RuntimeException.class)
    public ResultDTO<String> handleRuntimeException(RuntimeException e) {
        return ResultDTO.error(e.getMessage());
    }

    @ExceptionHandler(PermissionsException.class)
    public ResultDTO<String> permissionsException(PermissionsException permissionsException){
        return ResultDTO.failure(permissionsException.getMessage());
    }

    @ExceptionHandler(ParamsException.class)
    public ResultDTO<String> paramsException(ParamsException paramsException){
        return ResultDTO.error(paramsException.getMessage());
    }

}
